import {Component, OnInit} from '@angular/core';
import {RouterModule, Router} from '@angular/router';
import {ApiServiceService} from '../api.service'

@Component({
  selector: 'app-topnav',
  templateUrl: './topnav.component.html',
  styleUrls: ['./topnav.component.css'],
  providers: [ApiServiceService]
})
export class TopnavComponent implements OnInit {
  finishNum: number;
  version: string;
  logoUrl: string;

  constructor( private  router: Router,
  private apiserviceService: ApiServiceService
  ) {
  }

  ngOnInit() {
 this.version =  sessionStorage.product;
    this.logoUrl  = sessionStorage.logourl || '../../images/11.jpg';

    if(sessionStorage.finishNew == 0) {
      this.referenceShow();
      this.finishNum = 1;

      // this.apiserviceService.modifyFinishNew(this.finishNum,sessionStorage.uid).subscribe(res =>{
      //   console.log(res);


      //   if(res.init == 'success'){
      //     console.log("修改成功了")
      //   }

      // });

      console.log('这个是判断'+sessionStorage.finishNew);

    }else{

    }
  }

  referenceShow() {
    var tmpStr = window.location.href;
    console.log(tmpStr)
    console.log(tmpStr.split("/"));

    var space = (document.body.scrollWidth - 1262) / 2;
    console.log(space);
    var rf_onlineDevice_left:number = 151 + space;

    console.log(rf_onlineDevice_left);
    var rf_todayTask_left:number = 751 + space;
    console.log(rf_todayTask_left);

    var rf_state_bar_left:number = 761 + space;
    console.log(rf_state_bar_left);

    if (tmpStr.split("/")[tmpStr.split("/").length - 1] == "home" || tmpStr.split("/")[tmpStr.split("/").length - 1] == "moduleList" || tmpStr.split("/")[tmpStr.split("/").length - 1] == "") {
      document.getElementsByClassName("rf_onlineDevice")[0].setAttribute("style", "position: absolute;top: 400px;left:" + rf_onlineDevice_left + "px;");
      document.getElementsByClassName("rf_todayTask")[0].setAttribute("style", "position: absolute;top: 400px;left:" + rf_todayTask_left + "px;")


    } else {
      document.getElementsByClassName("rf_onlineDevice")[0].setAttribute("style", "display:none");
      document.getElementsByClassName("rf_todayTask")[0].setAttribute("style", "display:none")
    }
    document.getElementsByClassName("rf_menu")[0].setAttribute("style", "position: absolute;top: 200px;left:" + rf_onlineDevice_left + "px;");
    document.getElementsByClassName("rf_state_bar")[0].setAttribute("style", "position: absolute;top: 50px;left:" + rf_state_bar_left + "px;");


    document.body.style.overflow = "hidden";
    document.getElementsByClassName("reference")[0].setAttribute("style", "width:100%;height:100%;background: rgba(0, 0, 0, 0.21);top:0;left:0;bottom:0;right:0;"
      + "position: absolute;z-index: 1000;justify-content: center; align-items: center;");
    document.getElementsByClassName("reference")[0].addEventListener("click", function () {
      document.getElementsByClassName("reference")[0].setAttribute("style", "display:none");
      document.body.style.overflow = "auto";
    })

  }




  quit(){
    console.log('你进入了注销的页面');
   console.log(sessionStorage.uid + ':' + sessionStorage.ulevel);
   sessionStorage.clear();
   this.router.navigate(['login']);
    console.log(sessionStorage.uid + ':' + sessionStorage.ulevel);
    console.log('退出成功');

  }



}
